package athabasca.ca.model;

import java.util.Stack;

public class TrackedFeature extends FeatureConcept
{
	private float totalUsage;
	private Stack<FeatureUsage> usageHistory;
	
	public TrackedFeature()
	{
		super();
		totalUsage = 0;
		usageHistory = new Stack<FeatureUsage>();
	}
	
	public TrackedFeature(String featureName)
	{
		super(featureName);
		totalUsage = 0;
		usageHistory = new Stack<FeatureUsage>();
	}
	
	public TrackedFeature(String featureName, float totalUsage)
	{
		super(featureName);
		this.totalUsage = totalUsage;
		usageHistory = new Stack<FeatureUsage>();
	}
	
	public float getTotalUsage()
	{
		return totalUsage;
	}
	
	public void setTotalUsage(float totalUsage)
	{
		this.totalUsage = totalUsage;
	}
	
	public void updateUsageHistory(FeatureUsage newestUsage)
	{
		usageHistory.push(newestUsage);
		totalUsage += newestUsage.getCurrentValue();
	}
	
	public void clearUsageHistory()
	{
		totalUsage = 0;
		usageHistory.clear();
	}
	
	public void clearUsageHistory(int usageIdentifier)
	{
		FeatureUsage removedUsage = usageHistory.remove(usageIdentifier);
		if(removedUsage != null)
		{
			totalUsage -= removedUsage.getCurrentValue();
		}
		else
		{
			System.out.println("ERROR- usagePeriod not found!");
		}
	}
	
	public FeatureUsage getMostRecentFeatureUsage ( )
	{
		return this.usageHistory.peek ( );
	}
	
}
